package com.ruoyi.ahs.service.impl;

import com.ruoyi.ahs.cache.AhsCache;
import com.ruoyi.ahs.service.IRushTaskDtoService;
import com.ruoyi.ahs.util.RushTaskDto;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * TODO to describe RushTaskDtoService
 *
 * @author 辛凤文
 * @since 1.0
 */
@Service
public class RushTaskDtoService implements IRushTaskDtoService {

    @Async
    public void addTask(RushTaskDto task) {
        if (task != null) {
            AhsCache.rushTaskCacheMap.put(task.getId(), task);
            task.start();
        }
    }

    public void removeTask(Long id) {
        RushTaskDto task = AhsCache.rushTaskCacheMap.remove(id);
        if (task != null) {
            task.stop();
        }
    }
}
